<%@ page language="java" import="java.util.*,com.ruohi.util.common.*" pageEncoding="UTF-8"%><%
	String product_no = CommonString.getFormatPara(request.getParameter("product_no"));	

	String tablePrefix = Env.getInstance().getProperty("table_prefix");
	String tableName = "gift_product";
	String channelUUID = CommonString.getFormatPara(request.getParameter("channel_uuid"));
	String fileds = "id,uuid,no,name,category,brand,storage,price_promotion,weight,view_count,is_show,order_no";
	String whereStr = " and is_package=1";
	if(!product_no.equals("")){
		//whereStr += " and product_no='" + product_no + "'";
	}
	String orderByStr = " order_no desc,id desc ";
	
	List<Map> brandList = (ArrayList)application.getAttribute("giftBrandList");
	//产品类别
	Map categoryMap = new TreeMap();
	List<Map> categoryList = (List)application.getAttribute("giftCategoryList");
	String n = "";
	String name = "";
	if(categoryList != null){
		for(Map m : categoryList){
			n = (String)m.get("no");
			name = (String)m.get("name");
			name = CommonForm.getHtmlSpaceByString((String)m.get("parent_no"))+name;
			categoryMap.put(n,name);
		}
	}
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title><%=Env.getInstance().getProperty("project_name") %></title>
	<link href="/plugin/ui/ligerUI/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
	<link href="/backend/style/style.css" rel="stylesheet" type="text/css" />
	<script src="/plugin/jquery/jquery.min.js" type="text/javascript"></script>
  </head>
  <body>
  	<div class="searchForm">
  		<div class="searchCondition">
	  		<div class="searchLeft">套餐名称</div>
	  		<div class="searchRight">
	  			<input type="text" style="width: 120px;" name="name" class="jr_text" id="name" />
	  		</div>
  		</div>
  		<div class="searchBtn">
  			<input type="button" class="btn" onclick="doSearch();" value="查询" />
  			<input type="button" class="btn" onclick="doClearForm();" value="重置" />
  		</div>
  	</div>
	<div style="clear: left;"></div>
	<div class="l-loading" style="display: block" id="pageloading"></div> 
	<div id="maingrid" style="margin: 0; padding: 0"></div>
	<div style="display: none;"></div>
  </body>
</html>
<script src="/plugin/ui/ligerUI/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="/backend/scripts/common.js" prefix="<%=tablePrefix %>" type="text/javascript"></script>
<script type="text/javascript">
	var grid;
	var tableName = "<%=tableName %>";
	var channelUUID = '<%=channelUUID%>';
	var fields = "<%=fileds %>";
	var whereStr = "<%=whereStr %>";
	var orderBy = "<%=orderByStr %>";
	var columnsArr = [];
	var url = "";
	var conditionStr = "";
	var params = [];
	var myToolbar = {
        items: [{
            text: '增加',
            click: function(){
                addAndEdit(undefined);
            },
            icon: 'add'
        },{
        	text: "删除",
        	click: function(){
        		toolbarDel({
					'eventAfter':'deletePackageProduct'
				});
        	},
        	icon: "delete"
        },{
            text: '打开查询',
            click: function(){
                closeAndOpen();
            },
            icon: 'right'
        }]
    };
	jQuery(function() {
		params.push({'name':'enumNo','value':'106013','fileName':'test'});
		grid = new Dev21sunGrid({
			toolbar:myToolbar
		});
		jQuery("#pageloading").hide();
	});
	//列数组
	columnsArr =  [ 
	{ display : '套餐名称', name : 'name'  , id : 'no', align : 'left' , type : 'string' , width : 280 , render : function(row){
			return "<a class='link' href='javascript:void(0);' onclick='addAndEdit("+row.__index+");'>"+row.name+"</a>";
			}
		} ,
	{ display : '套餐编号', name : 'no'  , align : 'left' , type : 'string' , width : 150 , render : function(row){
			return "<a class='link' href='javascript:void(0);' onclick='addAndEdit("+row.__index+");'>"+row.no+"</a>";
		}
	}  ,
	{ display:"套餐价格", name:"price_promotion", align:"left", type:"string", width:100, render:function(row){
		return row.price_promotion.toFixed(2);
	} }
	];
	
	function addAndEdit(index){
		if(undefined==index){//如果是增加
			toolbarAdd({
				width:800,
				height:630,
				title:"增加套餐",
				params : {
	    			channel_uuid : "<%=channelUUID %>"
	    		}
			});
		}else{//如果是修改
	    	var row = grid.getRow(index);
	    	toolbarAdd({width:800,height:630,title:'编辑套餐'},row.uuid);
		}
    }
	/*列表页条件查询*/
	function doSearch(){
		params = [];
		conditionStr = "";
		var name = jQuery("#name").val();
		if(''!=jQuery.trim(name)){
			conditionStr += " and name like '%"+name+"%' ";
		}
		params.push({'name':'tableName','value':tableName});
		params.push({'name':'enumNo','value':'106013'});
		params.push({'name':'fields','value':fields});
		params.push({'name':'whereStr','value':conditionStr});
		params.push({'name':'orderBy','value':orderBy});
		grid.options.parms=params;
		grid.loadData();
	}

	/**
	 * 列表删除方法
	 * 
	 * @param {}
	 *            arg 删除时要传的参数
	 */
	function toolbarDel(arg) {
		if (typeof(arg) == 'undefined' || arg == null) {
			arg = {};
		}
		var checkedRows = grid.getCheckedRows();
		if (checkedRows.length <= 0) {
			return;
		}
		// 遍历所有的选中行，如果是没有UUID，则移除
		jQuery.each(checkedRows, function(index, data) {
			if (typeof(this.uuid) == 'undefined') {
				jrDeleteRow(this.__index);
			}
		});
		jrConfirm("确定删除选中项吗？", function(v) {
			if (v) {
				var checkedRows = grid.getCheckedRows();
				var idStr = "";
				var noStr = "";
				for (var i = 0; i < checkedRows.length; i++) {
					idStr += "'" + checkedRows[i].uuid + "',";
					noStr += "'" + checkedRows[i].no + "',";
				}
				if (idStr.indexOf(",") != -1) {
					idStr = idStr.substring(0, idStr.length - 1);
					noStr = noStr.substring(0, noStr.length - 1);
				}
				arg.del_id = idStr;
				arg.del_no = noStr;
				if ('undefined' == typeof(arg.tableName)) {
					arg.tableName = tableName;
				}
				executeDel(arg);
			}
		});
	}
</script>